//
//  YZMSaleTradeModel.m
//  YZMicroStock
//
//  Created by wangminhong on 16/4/14.
//  Copyright © 2016年 cqjr. All rights reserved.
//

#import "YZMSaleTradeModel.h"
#import "Mantle+Utils.h"

@implementation YZMSaleTradeModelForApart

+ (NSDictionary *)JSONKeyPathsByPropertyKey {
    
    return @{@"amount":@"amount",
             @"price":@"price",
             @"time":@"time",
             };
}

+ (NSValueTransformer *)amountJSONTransformer
{
    return [NSValueTransformer valueTransformerForName: MTLStringDoubleTransformerName];
}

+ (NSValueTransformer *)priceJSONTransformer
{
    return [NSValueTransformer valueTransformerForName: MTLStringDoubleTransformerName];
}

+ (NSValueTransformer *)timeJSONTransformer
{
    return [NSValueTransformer valueTransformerForName: MTLDoubleDateTransformerName];
}

- (instancetype)copyWithZone:(NSZone *)zone{
    
    YZMSaleTradeModelForApart *copy = [[[self class] allocWithZone:zone] init];
    copy.amount = self.amount;
    copy.price = self.price;
    copy.time = [self.time copyWithZone:zone];
    
    return copy;
}

@end

@implementation YZMSaleTradeModel

+ (NSDictionary *)JSONKeyPathsByPropertyKey {
    
    return @{@"buyMoney":@"money",
             @"principal":@"gainPrincipal",
             @"buyPriceDeal":@"buyPriceDeal",
             @"sellPriceDeal":@"sellPriceDeal",
             @"dealTime":@"dealTime",
             @"tid":@"id",
             @"quitLoss":@"quitLoss",
             @"status":@"status",
             @"stockCode":@"stockCode",
             @"stockName":@"stockName",
             @"holdCount":@"volumeHold",
             @"sumCount":@"volumeDeal",
             @"tradingDeferCharge":@"tradingDeferCharge",
             @"unHanldHoldDeferCharge":@"unHanldHoldDeferCharge",
             @"holdDays":@"holdDays",
             @"tradingList":@"tradingRecordList",
             @"owedMoney":@"arrearsBalance",
             @"deferProfit":@"deferProfit",
             @"lossPrincipal":@"lossPrincipal",
             @"schemeId":@"schemeId",
             };
}

- (void)setNilValueForKey:(NSString *)key
{
    
}

- (instancetype)initWithDictionary:(NSDictionary *)dictionaryValue error:(NSError **)error{
    
    self = [super initWithDictionary:dictionaryValue error:error];
    if (self) {
       
        for (YZMSaleTradeModelForApart *apart in self.tradingList) {
            
            self.apartCount += apart.amount;
        }
    }
    
    return self;
}


+ (NSValueTransformer *)buyMoneyJSONTransformer
{
    return [NSValueTransformer valueTransformerForName: MTLStringDoubleTransformerName];
}

+ (NSValueTransformer *)gainPrincipalJSONTransformer
{
    return [NSValueTransformer valueTransformerForName: MTLStringDoubleTransformerName];
}

+ (NSValueTransformer *)buyPriceDealJSONTransformer
{
    return [NSValueTransformer valueTransformerForName: MTLStringDoubleTransformerName];
}

+ (NSValueTransformer *)sellPriceDealJSONTransformer
{
    return [NSValueTransformer valueTransformerForName: MTLStringDoubleTransformerName];
}

+ (NSValueTransformer *)dealTimeJSONTransformer
{
    return [NSValueTransformer valueTransformerForName: MTLDoubleDateTransformerName];
}

+ (NSValueTransformer *)quitLossJSONTransformer
{
    return [NSValueTransformer valueTransformerForName: MTLStringDoubleTransformerName];
}

+ (NSValueTransformer *)tradingDeferChargeJSONTransformer
{
    return [NSValueTransformer valueTransformerForName: MTLStringDoubleTransformerName];
}

+ (NSValueTransformer *)unHanldHoldDeferChargeJSONTransformer
{
    return [NSValueTransformer valueTransformerForName: MTLStringDoubleTransformerName];
}

+ (NSValueTransformer *)owedMoneyJSONTransformer
{
    return [NSValueTransformer valueTransformerForName: MTLStringDoubleTransformerName];
}

+ (NSValueTransformer *)deferProfitJSONTransformer
{
    return [NSValueTransformer valueTransformerForName: MTLStringDoubleTransformerName];
}

+ (NSValueTransformer *)tradingListJSONTransformer
{
    return [MTLJSONAdapter arrayTransformerWithModelClass: [YZMSaleTradeModelForApart class]];
}

- (BOOL)isEqual:(YZMSaleTradeModel *)object{
    
    if ([object class] == [self class]) {
        return self.tid == object.tid;
    }
    return NO;
}

- (NSUInteger)hash {
    
    return [[NSString stringWithFormat:@"%@",@(self.tid)] hash];
}

- (instancetype)copyWithZone:(NSZone *)zone{
    
    YZMSaleTradeModel *copy = [[[self class] allocWithZone:zone] init];
    copy.buyMoney = self.buyMoney;
    copy.principal = self.principal;
    copy.buyPriceDeal = self.buyPriceDeal;
    copy.sellPriceDeal = self.sellPriceDeal;
    copy.dealTime = [self.dealTime copyWithZone:zone];
    
    copy.tid = self.tid;
    copy.quitLoss = self.quitLoss;
    copy.status = self.status;
    copy.stockCode = [self.stockCode copyWithZone:zone];
    copy.stockName = [self.stockName copyWithZone:zone];
    copy.holdCount = self.holdCount;
    copy.sumCount = self.sumCount;
    copy.owedMoney = self.owedMoney;
    
    copy.tradingList = [self.tradingList copyWithZone:zone];
    copy.tradingDeferCharge = self.tradingDeferCharge;
    copy.unHanldHoldDeferCharge = self.unHanldHoldDeferCharge;
    copy.holdDays = self.holdDays;
    
    return copy;
}


@end
